/*
 * @Author: your name
 * @Date: 2021-05-19 16:11:41
 * @LastEditTime: 2021-05-26 19:50:42
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /xiangpan-admin/src/pages/chain/addChain/index.tsx
 */ /*
 * @Author: your name
 * @Date: 2021-04-24 16:43:48
 * @LastEditTime: 2021-04-24 17:40:26
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /admin/src/pages/CourseInfo/editCourse/index.tsx
 */
import React, { useEffect } from 'react';
import HeaderForm from '@/components/form';
import { IFormTypeEnum } from '@/components/form/formComponent';
import { FormInstance, Modal, Row } from 'antd';
import { add_chain, delete_chain, edit_chain } from '@/services/pages';
import { useRequest } from 'umi';
import useObj from '@/use/useObj';

interface IProps {
  visible: boolean;
  close: () => void;
  refresh: () => void;
  row?: any;
}

const ChainModal = (props: IProps) => {
  const List = [
    {
      key: 'chain_name',
      type: IFormTypeEnum.Input,
      label: '连锁店名称',
      rules: [{ required: true }],
    },
  ];

  const onFinish = async (values: any, form: FormInstance) => {
    console.log(form, 'form===');
    if (props.row?.chain_id) {
      await edit_chain({ ...values, chain_id: props.row.chain_id });
    } else {
      await add_chain(values);
    }
    props.close();
    props.refresh();
  };
  console.log(props.row, 'props.row=');

  return (
    <Modal
      visible={props.visible}
      title={props.row?.chain_id ? '编辑连锁店' : '添加连锁店'}
      footer={null}
      onCancel={props.close}
    >
      <HeaderForm
        labelwidth={100}
        layout="horizontal"
        list={List}
        onSubmit={onFinish}
        initialValues={props.row}
      />
    </Modal>
  );
};
export default ChainModal;
